package com.globallogic.draw;

import java.util.Collection;
import java.util.TreeSet;

import com.globallogic.inout.Out;

public class Drawer <T extends Drawable> {

	public void add(T drawObject) {
		
		drawObjectList.add(drawObject);
		
	};
	
	public void draw() {
		
		final int MAX_SLOT = 40;
		
		float scale = 1;
		int slotLenght;
		int cnt = 0;
		
		slotLenght = getMax();
		
		if (slotLenght > MAX_SLOT) {
			
			scale = slotLenght / MAX_SLOT;
			slotLenght = (int) (slotLenght * scale);
			
		}
		
		for (T drawObject : drawObjectList) {
			
			drawObject.draw(scale, slotLenght);
			cnt++;
		}
		
		if (0 == cnt) {
			
		    Out.printLn("No object of this type has been added");
			
		} 
		
	};
	
	private int getMax() {
        
		int maxLenght = 0;
		
		for (T drawObject : drawObjectList) {
			
			if (maxLenght < drawObject.getLenght()){
				
				maxLenght = drawObject.getLenght();
				
			}
			
		}
		
		return maxLenght;
	   	
	}
	
	private Collection<T> drawObjectList = new TreeSet<T>();
	
}
